<?php

namespace Yi\Wechat;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport;

class WechatServiceProvider extends ServiceProvider
{
    public function boot()
    {

        $this->register();
        $this->loadRoutesFrom(__DIR__ . '/Route.php');
    }

    public function register()
    {
        // 发布配置文件
        // $this->publishes([
        //     __DIR__ . '/config/permission_config.php' => config_path('permission_config.php'),
        // ]);

        //以单例模式注册InviteCode类实例，注意这里注册为InviteCode，后面Facade门面将以InviteCode命名，否则找不到类的实例
        // $this->app->singleton('YiPermission', function ($app) {
        //     return new YiPermission($app['config']);
        // });
    }

    protected function sqlLog()
    {
        DB::listen(function ($query) {
            $data = [
                'sql' => $query->sql,
                'bindings' => $query->bindings,
                'time' => $query->time,
            ];
            Log::info(json_encode($data));
        });
    }
}
